// vite.config.js
import { defineConfig,loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig(( { mode }) => {
  // 根据不同环境加载配置
  const env = loadEnv(mode, process.cwd(),"")

  return {
    base: env.VITE_BASE_URL,
    server: {
      host: '0.0.0.0',           // 监听所有网络接口
      port: 3000,                // 可选：指定固定端口（如3000）
      strictPort: false,         // 如果端口被占用，尝试下一个可用端口
      hmr: {
        host: '192.168.31.86'    // 替换为你的本机局域网IP（可选）
      }
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [VantResolver(), ElementPlusResolver()],
      }),
      Components({
        resolvers: [VantResolver(), ElementPlusResolver()],
      }),
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
  }
})
